package com.cicc.controller;

import com.cicc.domain.Account;
import com.cicc.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;


@Controller
@RequestMapping(value ="account" ,produces = "text/html;charset=UTF-8")
public class AccountController {
    @Autowired
    private AccountService accountService;
    //添加用户
    @RequestMapping("save")
    @ResponseBody
    public String  save (Account account){
        accountService.save(account);
        return "数据保存成功";
    }

    //查询
    @RequestMapping("/findAll")
    public ModelAndView findAll(){
        List<Account>accountList = accountService.findAll();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("accountList",accountList);
        modelAndView.setViewName("accountList");
        return modelAndView;
    }
}
